package com.aaa.sbm.controller;

import com.aaa.sbm.entity.Dept;
import com.aaa.sbm.service.DeptService;
import com.aaa.sbm.service.HandlerFileService;
import com.aaa.sbm.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

@RestController
@RequestMapping("/dept")
public class DeptController {
    @Autowired
    private DeptService deptService;
    @Autowired
    private HandlerFileService handlerFileService;

    @GetMapping("list")
    public Result list(){
        return deptService.list();
    }

    @GetMapping("page")
    public Result page(@RequestParam Map map){
        return deptService.page(map);
    }

    @GetMapping("getById")
    public Result getById(Integer deptNo){
        return deptService.getById(deptNo);
    }

    @PostMapping("add")
    public Result add(@RequestBody Dept dept){
        return deptService.add(dept);
    }

    @DeleteMapping("delete")
    public Result delete(Integer deptNo){
        return deptService.delete(deptNo);
    }

    @PostMapping("update")
    public Result update(@RequestBody Dept dept){
        return deptService.update(dept);
    }
    /**
     * 文件上传方法
     * @param file
     * @return
     */
    @RequestMapping("uploadFile")
    public Object  uploadFile(@RequestParam MultipartFile file){
        return handlerFileService.fileUpload(file,"imgs/dept/a/b/c/d");
    }
}
